<template>
    <div>
     <h3>管理员登录</h3>
     <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">管理员名称</td>
                <td>
                    <input type="text" v-model="querinfo.username"/>
                </td>
            </tr>
            <tr>
                <td align="right">管理员密码</td>
                <td>
                    <input type="password" v-model="querinfo.userpass"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="登录" class="btn btn-info" @click="ok"/>
                </td>
            </tr>
        </tbody>
     </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

import {useUserStore} from '@/stores/user'
const abc=useUserStore();


let querinfo: any = reactive({
    username: "",
    userpass: ""
})

const ok = () => {
    if (querinfo.username == "") 
    {
        alert("管理名称不能为空");
        return;
    }
    if (querinfo.userpass == "") {
        alert("密码不能为空");
        return;
    }
    axios({
        url: '/api/Admin/AdminLoGin',
        method: 'get',
        params: querinfo
    })
        .then(res => {
            if (res.data == -1) {
                alert("管理员名称错误");
                return;
            }
            if (res.data == -2)
             {
                alert("密码错误");
                return;
            }
            
                alert("登录成功");
                abc.userinfo=res.data;
                router.push('/houseTypeAdd');
                return;
            
        })
        .catch(err => {

        })
}



</script>

<style scoped>

</style>